home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / LITTLE / BMSRC.ZIP / ENGINE.S < prev    next >
Encoding:
Text File  |  1996-11-23  |  15.4 KB  |  493 lines

  1. *=======================================================*
  2. *    Display-engine: latest update 25/03/96        *
  3. *=======================================================*
  4. *    Call all display modules in correct order    *
  5. *=======================================================*
  6.  
  7. *-------------------------------------------------------*
  8.     txtlong
  9. *-------------------------------------------------------*
  10. display_engine:
  11. *-------------------------------------------------------*
  12.     moveq        #0,d1
  13.     move.w        width,d1
  14.     move.l        #256<<4,d0
  15.     swap        d0
  16.     divu.l        d1,d0
  17.     neg.l        d0
  18.     move.l        d0,skyx
  19.  
  20.     move.w        fheight,d1
  21.     mulu.w        #128,d1
  22.     moveq        #0,d0
  23.     move.w        sys_default_height,d0
  24.     divu.l        d0,d1
  25. ;    divu.l        #default_height,d1
  26.  
  27. ;    move.l        #128,d1
  28.  
  29.     move.l        #128,d0
  30.     swap        d0
  31.     divu.l        d1,d0
  32.     move.l        d0,skyy
  33.  
  34.     moveq        #0,d0
  35.     move.w        pangle,d0
  36.     add.w        #$10000/8,d0
  37.     lsl.l        #8,d0
  38.     lsl.l        #2+4,d0
  39.     move.l        d0,xoff
  40. *-------------------------------------------------------*
  41. *    Calculate window base-address (centering)    *
  42. *-------------------------------------------------------*
  43.     jsr        centre_screen
  44.  
  45. *-------------------------------------------------------*
  46. *    Reset wall & floor buffers for this frame    *
  47. *-------------------------------------------------------*
  48.     move.l        #transparent_space,transparent_array
  49.     clr.w        transparent_count
  50.     move.l        #zone_space,zone_ptr
  51.     clr.b        zone_space
  52.     bsr        init_wall_lists
  53. *-------------------------------------------------------*
  54. *    Init display variables for this frame        *
  55. *-------------------------------------------------------*
  56.     bsr        update_display_struct
  57. *-------------------------------------------------------*
  58. *    Transfer frame-critical details to DSP        *
  59. *-------------------------------------------------------*
  60.     lea        display_struct,a6
  61.     move.l        sinpangle,d1
  62.     move.l        cospangle,d2
  63.     lsl.l        #8-2,d1
  64.     lsl.l        #8-2,d2
  65.     lea        DSPHostStat.w,a2
  66.     lea        DSPHost16.w,a0
  67.     moveq        #newscene_command,d0
  68.     dspwaitwrite.0    (a2)
  69.     move.w        d0,(a0)
  70.     dspwaitwrite.0    (a2)
  71.     move.w        display_px(a6),(a0)
  72.     dspwaitwrite.0    (a2)
  73.     move.w        display_py(a6),(a0)
  74.     dspwaitwrite.0    (a2)
  75.     move.w        pangle,(a0)
  76.     lea        DSPHost32.w,a0
  77.     dspwaitwrite.0    (a2)
  78.     move.l        d1,(a0)
  79.     dspwaitwrite.0    (a2)
  80.     move.l        d2,(a0)
  81. *-------------------------------------------------------*
  82. *    Init lighting effects for this frame        *    
  83. *-------------------------------------------------------*    
  84.     bsr        set_lighting
  85. *-------------------------------------------------------*
  86. *    Clearscreen for resizing window & debugging    *
  87. *-------------------------------------------------------*
  88.     ifd        frsb
  89.  
  90.     tst.b        refresh
  91.     beq.s        .no
  92.     move.b        #1,refresh
  93.     move.l        ScreenLog,a0
  94.     bsr        clearscreen
  95.     move.b        #1,refresh
  96.     move.l        ScreenPhy,a0
  97.     bsr        clearscreen
  98.     clr.b        refresh
  99. .no:
  100.     elseif
  101.  
  102.     move.l        ScreenLog,a0
  103.     bsr        clearscreen
  104.  
  105.     endc
  106. *-------------------------------------------------------*
  107. *    Descend BSP tree & build scenery        *
  108. *-------------------------------------------------------*
  109.     bsr        descend_bsp
  110. *-------------------------------------------------------*
  111. *    Render floors & ceilings            *
  112. *-------------------------------------------------------*
  113.     bsr        render_flats
  114. *-------------------------------------------------------*
  115. *    Render transparet wall & sprite segments    *
  116. *-------------------------------------------------------*
  117.     bsr        render_transparent
  118.  
  119. ;    bsr        render_walls
  120.  
  121. *-------------------------------------------------------*
  122.     rts
  123.  
  124. *-------------------------------------------------------*
  125. toggle_h_detail:
  126. *-------------------------------------------------------*    
  127.     not.b        halfrows
  128.     bsr        select_window
  129.     rts
  130.  
  131. *-------------------------------------------------------*
  132. toggle_v_detail:
  133. *-------------------------------------------------------*
  134.     tst.b        halflines
  135.     bne.s        .normal_detail
  136. *-------------------------------------------------------*
  137. *    Switch to low detail, if dline mode is free    *
  138. *-------------------------------------------------------*
  139. .low_detail:
  140. *-------------------------------------------------------*
  141. *    Check interlace first - this looks better    *
  142. *-------------------------------------------------------*
  143.     tst.b        ilace_active
  144.     beq.s        .noil
  145. *-------------------------------------------------------*
  146. *    Interlace is on - so turn it off!        *
  147. *-------------------------------------------------------*
  148.     sf        ilace_active
  149.     st        halflines
  150.     bra.s        .done
  151. *-------------------------------------------------------*
  152. *    Can't turn off ilace, so try dline        *
  153. *-------------------------------------------------------*
  154. .noil:    tst.b        dline_active
  155.     bne.s        .err
  156. *-------------------------------------------------------*
  157. *    Low detail is available, so go for it!        *
  158. *-------------------------------------------------------*
  159.     st        dline_active
  160.     st        halflines
  161.     bra.s        .done
  162. *-------------------------------------------------------*
  163. *    Switch to normal detail mode            *
  164. *-------------------------------------------------------*
  165. .normal_detail:
  166. *-------------------------------------------------------*
  167. *    Check dline first - this looks better        *
  168. *-------------------------------------------------------*
  169.     tst.b        dline_active
  170.     beq.s        .nodl
  171. *-------------------------------------------------------*
  172. *    dline used - so turn it off            *
  173. *-------------------------------------------------------*
  174.     sf        dline_active
  175.     sf        halflines
  176.     bra.s        .done
  177. *-------------------------------------------------------*
  178. *    dline not used - must resort to interlace    *
  179. *-------------------------------------------------------*
  180. .nodl:    st        ilace_active
  181.     sf        halflines
  182. *-------------------------------------------------------*
  183. .done:    bsr        select_window
  184. .err:    rts
  185.  
  186. *-------------------------------------------------------*
  187. *    Init wall edgebuffer lists for next frame    *
  188. *-------------------------------------------------------*
  189.     txtlong
  190. *-------------------------------------------------------*
  191. init_wall_lists:
  192. *-------------------------------------------------------*
  193.     lea        maxy,a0
  194.     lea        miny,a1
  195.     move.w        height,d1
  196.     moveq        #0,d2
  197.     moveq        #-1,d3
  198.     move.w        width,d0
  199.     subq.w        #1,d0
  200.     lea        occlusion_list,a2
  201. .for_i:    move.w        d1,(a0)+
  202.     move.w        d2,(a1)+
  203.     move.b        d3,(a2)+
  204.     dbra        d0,.for_i
  205.     clr.w        wallruncount
  206.     lea        display_struct,a6
  207.     move.w        width,display_columns(a6)
  208.     rts
  209.  
  210. *-------------------------------------------------------*
  211. *    Set up general (engine) structures & tables    *
  212. *-------------------------------------------------------*
  213.     txtlong
  214. *-------------------------------------------------------*
  215. init_displaystruct:
  216. *-------------------------------------------------------*
  217.     lea        display_struct,a6
  218. *-------------------------------------------------------*
  219. *    Initialise pointers to WAD room data        *
  220. *-------------------------------------------------------*
  221.     move.l        Seg_Array,display_segs(a6)
  222.     move.l        Sector_Array,display_sectors(a6)
  223.     move.l        SSector_Array,display_ssectors(a6)
  224.     move.l        Side_Array,display_sidedefs(a6)
  225.     move.l        Line_Array,display_linedefs(a6)
  226.     move.l        Vertex_Array,display_vertices(a6)
  227.     move.l        Node_Array,display_nodes(a6)
  228.     move.w        #42,display_ph(a6)
  229.     rts
  230.  
  231. *-------------------------------------------------------*
  232. *    Update general (engine) display structure    *
  233. *-------------------------------------------------------*
  234.     txtlong
  235. *-------------------------------------------------------*
  236. update_display_struct:
  237. *-------------------------------------------------------*
  238.     lea        display_struct,a6
  239. *-------------------------------------------------------*
  240. *    Set up player position and angle        *
  241. *-------------------------------------------------------*
  242.     move.l        sinpangle,d3
  243.     move.l        cospangle,d4
  244.     asr.l        #2,d3
  245.     asr.l        #2,d4
  246.     move.w        d3,display_sina(a6)
  247.     move.w        d4,display_cosa(a6)
  248.     move.w        px,display_px(a6)
  249.     move.w        py,display_py(a6)
  250. *-------------------------------------------------------*
  251. *    Calculate base address of octant routine    *
  252. *-------------------------------------------------------*
  253.     st        display_firstssec(a6)
  254. *-------------------------------------------------------*
  255.     rts
  256.     
  257. *-------------------------------------------------------*
  258. *    Select new display window size            *
  259. *-------------------------------------------------------*
  260.     txtlong
  261. *-------------------------------------------------------*
  262. select_window:
  263. *-------------------------------------------------------*
  264.     pushall
  265.     moveq        #10,d1
  266.     move.w        window_size,d2
  267.     cmp.w        #256,d2
  268.     bpl.s        .ok1
  269.     move.w        #256,d2
  270. .ok1    cmp.w        #1<<10,d2
  271.     bmi.s        .ok2
  272.     move.w        #1<<10,d2
  273. .ok2:    move.w        d2,window_size
  274. *-------------------------------------------------------*
  275. *    Recalculate window size                *
  276. *-------------------------------------------------------*
  277.     move.w        d2,d3
  278.     move.w        d2,d4
  279.     move.w        d2,d5
  280.     mulu.w        viewport_width,d3
  281.     mulu.w        viewport_height,d4
  282.     mulu.w        sys_expanded_height,d5
  283. ;    mulu.w        #expanded_height,d5
  284.     lsr.l        d1,d3
  285.     lsr.l        d1,d4
  286.     lsr.l        d1,d5
  287.     tst.b        halfrows
  288.     beq.s        .nhr1
  289.     lsr.w        d3
  290. .nhr1:    tst.b        halflines
  291.     beq.s        .nhl1
  292.     lsr.w        d4
  293.     lsr.w        d5
  294. .nhl1:    move.w        d3,width
  295.     move.w        d4,height
  296.     move.w        d5,fheight
  297. *-------------------------------------------------------*
  298. *    Recalculate aspect ratio            *
  299. *-------------------------------------------------------*
  300.     move.w        d3,d5
  301.     move.w        d4,d6
  302.     ext.l        d6
  303.     move.w        viewport_width,d0
  304.     mulu.w        aspect_ratio,d0
  305.     mulu.l        d0,d6
  306.     move.w        sys_default_width,d0
  307. ;    move.w        #default_width,d0
  308.     mulu.w        viewport_height,d0
  309.     divu.l        d0,d6
  310.     move.w        d6,rheight
  311. *-------------------------------------------------------*
  312. *    Recalculate texture ratio (1:1 or 2:1 or 1:2)    *
  313. *-------------------------------------------------------*
  314.     lsr.w        d5
  315.     move.w        d5,d0
  316.     tst.b        halfrows
  317.     beq.s        .nhr2
  318.     lsl.w        d0
  319. .nhr2:    tst.b        halflines
  320.     beq.s        .nhl2
  321.     lsr.w        d0
  322. .nhl2:    move.w        d5,hscale
  323.     mulu.w        aspect_ratio,d0
  324.     divu.w        sys_base_aspect,d0
  325. ;    divu.w        #base_aspect,d0
  326.     move.w        d0,vscale
  327. *-------------------------------------------------------*
  328. *    Update global display structure            *
  329. *-------------------------------------------------------*
  330.     lea        display_struct,a6
  331.     move.w        width,d1
  332.     move.w        d1,display_width(a6)
  333.     lsr.w        d1
  334.     move.w        d1,display_hwid(a6)
  335.     move.w        height,d1
  336.     move.w        d1,display_height(a6)
  337.     lsr.w        d1
  338.     move.w        d1,display_hhig(a6)
  339.     move.w        rheight,display_rheight(a6)
  340.     move.w        hscale,display_hscale(a6)
  341.     move.w        vscale,display_vscale(a6)
  342. *-------------------------------------------------------*
  343. *    Update addwall structure            *
  344. *-------------------------------------------------------*
  345. ;    lea        addwall_struct,a6
  346.     move.w        width,d1
  347.     move.w        d1,addwall_width(a6)
  348.     lsr.w        d1
  349.     move.w        d1,addwall_hwid(a6)
  350.     move.w        height,d1
  351.     move.w        d1,addwall_height(a6)
  352.     lsr.w        d1
  353.     move.w        d1,addwall_hhig(a6)
  354.     move.w        rheight,addwall_rheight(a6)
  355.     move.w        hscale,addwall_hscale(a6)
  356.     move.w        vscale,addwall_vscale(a6)
  357. *-------------------------------------------------------*
  358. *    3 CLS calls required to wipe log, phys & bak    *
  359. *-------------------------------------------------------*
  360.     move.b        clearcount,refresh
  361. *-------------------------------------------------------*
  362. *    Recalculate video display height        *
  363. *-------------------------------------------------------*
  364.     move.b        #1,adjust
  365. *-------------------------------------------------------*
  366. *    Resize DSP rendering zone            *
  367. *-------------------------------------------------------*
  368.     bsr        dsp_resizewindow
  369. *-------------------------------------------------------*
  370.     bsr        adjust_map
  371. *-------------------------------------------------------*
  372.     popall
  373.     rts
  374.  
  375. *-------------------------------------------------------*
  376. configure_viewport:
  377. *-------------------------------------------------------*
  378. *    Base image size on screen size            *
  379. *-------------------------------------------------------*
  380.     move.w        screen_w,d1
  381.     move.w        screen_h,d2
  382. *-------------------------------------------------------*
  383. *    Keep size within programmed limits        *
  384. *-------------------------------------------------------*
  385.     cmp.w        #max_xres,d1
  386.     bmi.s        .xok
  387.     move.w        #max_xres,d1
  388. .xok:    cmp.w        #max_yres,d2
  389.     bmi.s        .yok
  390.     move.w        #max_yres,d2
  391. *-------------------------------------------------------*
  392. *    Set up physical image width            *
  393. *-------------------------------------------------------*
  394. .yok:    move.w        d1,sys_default_width
  395. *-------------------------------------------------------*
  396. *    Set up expanded (fullscreen) image height    *
  397. *-------------------------------------------------------*
  398.     move.w        d2,sys_expanded_height
  399. *-------------------------------------------------------*
  400. *    Set up default image height            *
  401. *-------------------------------------------------------*
  402.     mulu.w        #168,d2                ; (arbitrary) 8:5 down-sizing calculation...
  403.     divu.w        #200,d2                ; this can be replaced!
  404.     move.w        d2,sys_default_height
  405. *-------------------------------------------------------*
  406. *    Set virtual (reference) ratio            *
  407. *-------------------------------------------------------*
  408.     move.w        sys_default_width,d0
  409.     mulu.w        #200,d0
  410.     divu.w        #320,d0
  411.     move.w        d0,sys_base_aspect
  412. *-------------------------------------------------------*
  413. *    Set physical ratios for VGA & RGB        *
  414. *-------------------------------------------------------*
  415.     move.w        sys_expanded_height,d0
  416.     move.w        d0,sys_vga_aspect
  417.     move.w        sys_default_height,d0
  418.     move.w        d0,sys_rgb_aspect
  419. *-------------------------------------------------------*
  420. *    Low-level viewport variables            *
  421. *-------------------------------------------------------*
  422.     move.w        sys_default_width,viewport_width
  423.     move.w        sys_default_height,viewport_height
  424.     move.w        sys_vga_aspect,aspect_ratio
  425.     rts
  426.  
  427. *-------------------------------------------------------*
  428. *    Command DSP to resize internal structures    *
  429. *-------------------------------------------------------*
  430.     txtlong
  431. *-------------------------------------------------------*
  432. dsp_resizewindow:
  433. *-------------------------------------------------------*
  434.     lea        DSPHostStat.w,a2
  435.     lea        DSPHost16.w,a0
  436.     moveq        #resize_command,d0
  437.     dspwaitwrite.0    (a2)
  438.     move.w        d0,(a0)
  439.     dspwaitwrite.0    (a2)
  440.     move.w        width,(a0)
  441.     dspwaitwrite.0    (a2)
  442.     move.w        height,(a0)
  443.     dspwaitwrite.0    (a2)
  444.     move.w        rheight,(a0)
  445.     dspwaitwrite.0    (a2)
  446.     move.w        hscale,(a0)
  447.     dspwaitwrite.0    (a2)
  448.     move.w        vscale,(a0)
  449. *-------------------------------------------------------*
  450. *    Clear structures with dummy new_ssector        *
  451. *-------------------------------------------------------*
  452.     moveq        #newssector_command,d0
  453.     dspwaitwrite.0    (a2)
  454.     move.w        d0,(a0)
  455.     rts
  456.         
  457. *-------------------------------------------------------*
  458. *    Doom engine subroutines                *
  459. *-------------------------------------------------------*
  460.  
  461.     include        bspd.s
  462.     include        shards.s
  463.     include        render.s
  464.     include        lighting.s
  465.     include        timing.s
  466.     include        tables.s
  467.  
  468. *-------------------------------------------------------*
  469.             datlong
  470. *-------------------------------------------------------*
  471.  
  472. viewport_width:        dc.w    0            ; window width
  473. viewport_height:    dc.w    0            ; window height
  474. aspect_ratio:        dc.w    0            ; vertical aspect
  475.     
  476. *-------------------------------------------------------*
  477.             bsslong
  478. *-------------------------------------------------------*
  479.  
  480. display_struct:        ds.b    display_len        ; general display structure
  481.  
  482. window_size:        ds.w    1            ; window size % factor
  483. width:            ds.w    1            ; current render-width
  484. height:            ds.w    1            ; current render-height
  485. fheight:        ds.w    1            ; relative maximum height
  486. rheight:        ds.w    1            ; [relative] aspect ratio height
  487. hscale:            ds.w    1            ; horizontal x-scaling factor
  488. vscale:            ds.w    1            ; vertical x-scaling factor
  489.  
  490. *-------------------------------------------------------*
  491.             txtlong
  492. *-------------------------------------------------------*
  493.